package com.pig4cloud.pig.base.service.impl;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.admin.api.feign.RemoteDictService;
import com.pig4cloud.pig.base.api.dto.ServicesDto;
import com.pig4cloud.pig.base.api.vo.ClustersVO;
import com.pig4cloud.pig.base.api.vo.ConfigsVO;
import com.pig4cloud.pig.base.api.vo.ServiceVO;
import com.pig4cloud.pig.base.api.vo.ServicesVO;
import com.pig4cloud.pig.base.config.BaseUtil;
import com.pig4cloud.pig.base.service.BaseService;
import lombok.AllArgsConstructor;
import sun.swing.StringUIClientPropertyKey;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * packageName com.pig4cloud.pig.base.service.impl
 *
 * @author marco
 * @className BaseServiceImpl (此处以class为例)
 * @date 2024/5/30
 * @description TODO
 */
@Service
@AllArgsConstructor
public class BaseServiceImpl implements BaseService {


	@Override
	public Page services(Page page,ServiceVO serviceVO) {
		String jsonpage = BaseUtil.services(serviceVO.getName(),serviceVO.getGroupName(),(int)page.getCurrent(), (int)page.getSize());
		if(StringUtil.isNotBlank(jsonpage)) {
			JSONObject jsonObject = JSONObject.parseObject(jsonpage);
			System.out.println(jsonObject);
			String pageList = String.valueOf(jsonObject.get("serviceList"));
			List<ServiceVO> list = JSON.parseArray(pageList, ServiceVO.class);
			page.setRecords(list);
		}
		return page;
	}

	@Override
	public List<ClustersVO> service(String name) {
		List<ClustersVO> list = new ArrayList<ClustersVO>();
		String jsonService= BaseUtil.service(name);
		if(StringUtil.isNotBlank(jsonService)) {
			JSONObject jsonObject = JSONObject.parseObject(jsonService);
			System.out.println(jsonObject);
			String pageList = String.valueOf(jsonObject.get("list"));
			list = JSON.parseArray(pageList, ClustersVO.class);
		}
		return list;
	}

	@Override
	public List<ConfigsVO> configs() {
		return null;
	}
}
